//
//  HotDatailCollectViewController.m
//  BeautifulShoppings
//
//  Created by GivenBmli on 16/9/14.
//  Copyright © 2016年 GivenBmli. All rights reserved.
//

#import "HotDatailCollectViewController.h"
#import "NetworkHandler.h"
#import "ToolDB.h"
#import "ToolModel.h"
#import "TAMacro.h"
@interface HotDatailCollectViewController ()
@property (nonatomic, strong)UIWebView *webView;
@property (nonatomic, strong)UIButton *like_Button;
@property (nonatomic,copy)NSString * name;
@property (nonatomic,copy)NSString * ID;
@property (nonatomic,copy)NSString * IMAGE;
@end

@implementation HotDatailCollectViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor redColor];
    UIButton *butt = [UIButton buttonWithType:UIButtonTypeCustom];
    [butt setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    butt.frame  = CGRectMake(0, 0, 50, 50);
    UIBarButtonItem *left= [[UIBarButtonItem alloc]initWithCustomView:butt];
    [butt addTarget:self action:@selector(clickLeft:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem =left;
    [self Playpicture];
}
- (void)Playpicture {
    self.like_Button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.like_Button.frame =CGRectMake(0, SCREEN_HEIGHT - SCREEN_HEIGHT / 10 - 64 , SCREEN_WIDTH , SCREEN_HEIGHT / 10);
    [self.like_Button setTitle:@"喜欢" forState:UIControlStateNormal];
    self.webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT )];
    [self.view addSubview:self.webView];
    [self.like_Button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self.like_Button setImage:[UIImage imageNamed:@"红心"] forState:UIControlStateNormal];
    [self.like_Button addTarget:self action:@selector(like:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.like_Button];

    // 属性传值第二步
    NSInteger URL = self.str;
    [NetworkHandler getDataByURLString:[NSString stringWithFormat:@"http://api.liwushuo.com/v2/items/%ld",(long)URL] BodyString:nil WithDataBlock:^(id result) {
        NSDictionary *dic = [result objectForKey:@"data"];
        self.detail_html = [dic objectForKey:@"detail_html"];
        [self.webView  loadHTMLString:self.detail_html baseURL:[NSURL fileURLWithPath: [[NSBundle mainBundle]  bundlePath]]];
    }];

}
- (void)like:(UIButton*)send{
    BOOL saved = NO;
    if (saved == NO) {
        [ToolDB createTableTwo];
        
        [self.like_Button setImage:[UIImage imageNamed:@"心"] forState:UIControlStateNormal];
        
//        NSString *sql2 = [NSString stringWithFormat:@"INSERT INTO t_Hot(title,cover_image_url,ID) VALUES('%@','%@',%@);", self.name,self.IMAGE,self.ID];
        
//        [ToolDB execSqlString:sql2];
        
    }else{
        
        [self.like_Button setImage:[UIImage imageNamed:@"红心"] forState:UIControlStateNormal];
        
        
//        NSString *sql2 = [NSString stringWithFormat:@"DELETE FROM t_Hot where title = '%@' and cover_image_url = '%@';", self.name,self.IMAGE];
//        
//        [ToolDB dele:sql2];
        
    }
}
- (void)clickLeft:(UIButton *)qwe {
    [self.navigationController popViewControllerAnimated:YES];
}
@end
